home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgramD2.iso
/
Visual Database
/
Visual dBase v5.5
/
SAMPLES1.PAK
/
CUSTOMER.WFM
< prev
next >
Wrap
Text File
|
1995-07-18
|
24KB
|
750 lines
*******************************************************************************
* PROGRAM: Customer.wfm
*
* WRITTEN BY: Borland Samples Group
*
* DATE: 12/93
*
* UPDATED: 5/95
*
* REVISION: $Revision: 1.110 $
*
* VERSION: Visual dBASE
*
* DESCRIPTION: This program displays information about the customers of a
* company. It contains entryfields and radio buttons with
* various customer information. A browse object displays
* orders made by this customer. To add, delete, and search
* for customers, a menu (Customer.mnu) is used. This form
* also has custom buttons (from Buttons.cc) to allow traversing
* through customers. Information can be viewed in either
* View mode or in Edit mode, which is toggled in the menu.
*
* PARAMETERS: None
*
* CALLS: Customer.mnu (Menu file)
* Buttons.cc (Custom Controls file)
* Orders.wfm (Orders detail form)
* Customer.qbe (View of tables)
*
* USAGE: DO Customer.wfm && Note that you can also DO Orders.wfm
*
*******************************************************************************
#include <Messdlg.h>
shell(.F., .T.)
create session
set talk off
set ldCheck off && To avoid language driver conflicts
** END HEADER -- do not remove this line*
* Generated on 05/23/95
*
parameter bModal
local f
f = new CUSTOMERFORM()
if (bModal)
f.mdi = .F. && ensure not MDI
f.ReadModal()
else
f.Open()
endif
CLASS CUSTOMERFORM OF FORM
Set Procedure to &_dbwinhome.samples\Buttons.cc Additive
this.EscExit = .F.
this.OnClose = CLASS::ONCLOSE
this.View = "CUSTOMER.QBE"
this.Text = "Customer -- View Mode"
this.Top = 0
this.Height = 21.5293
this.Width = 88.333
this.TopMost = .F.
this.PageNo = 1
this.Maximize = .F.
this.Minimize = .F.
this.Left = 1.5
this.MousePointer = 1
this.ColorNormal = "BtnFace"
this.MenuFile = "CUSTOMER.MNU"
DEFINE PREVBUTTON PREVCUSTBUTTON OF THIS;
PROPERTY;
Group .T.,;
Default .T.,;
Top 19.6191,;
Height 1.5566,;
Width 14.1504,;
OnClick CLASS::PREVIOUS,;
Left 1.3496
DEFINE NEXTBUTTON NEXTCUSTBUTTON OF THIS;
PROPERTY;
Group .F.,;
Top 19.6191,;
Height 1.5566,;
Width 14.2207,;
OnClick CLASS::NEXT,;
Left 16.2793
DEFINE PUSHBUTTON FIRSTCUSTBUTTON OF THIS;
PROPERTY;
Group .F.,;
Text "F&irst",;
Top 19.6191,;
Height 1.5566,;
Width 14.0869,;
PageNo 1,;
OnClick {;form.CheckCommit(form.inEditMode);go top},;
Left 31.0791,;
ColorNormal "BtnText/BtnFace",;
StatusMessage "Go to the first record."
DEFINE PUSHBUTTON LASTCUSTBUTTON OF THIS;
PROPERTY;
Group .F.,;
Text "&Last",;
Top 19.6191,;
Height 1.5566,;
Width 14.2168,;
PageNo 1,;
OnClick {;form.CheckCommit(form.inEditMode);go bottom},;
Left 45.9492,;
ColorNormal "BtnText/BtnFace",;
StatusMessage "Go to the last customer."
DEFINE RECTANGLE NAMEPHONEBOX OF THIS;
PROPERTY;
Text "Customer Info",;
Height 18.5635,;
Top 0.2598,;
Width 85.8164,;
PageNo 1,;
Left 1.3496,;
Border .T.,;
ColorNormal "BtnFace"
DEFINE TEXT NAMETEXT OF THIS;
PROPERTY;
Text "N&ame:",;
Top 1.3193,;
Height 1.3193,;
Width 10.8037,;
PageNo 1,;
Left 2.0293,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 5
DEFINE ENTRYFIELD NAMEENTRY OF THIS;
PROPERTY;
ColorHighLight "B+/W*",;
Top 1.3193,;
Height 1.3193,;
Width 53.9805,;
Enabled .F.,;
PageNo 1,;
DataLink "CUSTOMER->NAME",;
Left 13.5195,;
OnChange CLASS::CHANGESMADE,;
Border .T.,;
ColorNormal "N/BtnFace"
DEFINE TEXT CUSTNOTEXT OF THIS;
PROPERTY;
Text "Customer #:",;
Top 1.3193,;
Height 1.3193,;
Width 13.5537,;
PageNo 1,;
Left 70.2793,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 3
DEFINE ENTRYFIELD CUSTNOENTRY OF THIS;
PROPERTY;
ColorHighLight "B+/W*",;
Top 2.6592,;
Height 1.3193,;
Width 11.5537,;
Enabled .F.,;
PageNo 1,;
DataLink "CUSTOMER_N",;
Left 70.2793,;
OnChange CLASS::CHANGESMADE,;
Border .T.,;
ColorNormal "N/BtnFace"
DEFINE TEXT STREETTEXT OF THIS;
PROPERTY;
Text "&Street:",;
Top 2.6592,;
Height 1.3193,;
Width 10.8037,;
PageNo 1,;
Left 2.0293,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 5
DEFINE ENTRYFIELD STREETENTRY OF THIS;
PROPERTY;
ColorHighLight "B+/W*",;
Top 2.6592,;
Height 1.3193,;
Width 53.9805,;
Enabled .F.,;
PageNo 1,;
DataLink "STREET",;
Left 13.5195,;
OnChange CLASS::CHANGESMADE,;
Border .T.,;
ColorNormal "N/BtnFace"
DEFINE TEXT CITYTEXT OF THIS;
PROPERTY;
Text "Cit&y:",;
Top 3.9795,;
Height 1.3145,;
Width 10.8037,;
PageNo 1,;
Left 2.0293,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 5
DEFINE ENTRYFIELD CITYENTRY OF THIS;
PROPERTY;
ColorHighLight "B+/W*",;
Top 3.9795,;
Height 1.3145,;
Width 22.3135,;
Enabled .F.,;
PageNo 1,;
DataLink "CITY",;
Left 13.5195,;
OnChange CLASS::CHANGESMADE,;
Border .T.,;
ColorNormal "N/BtnFace"
DEFINE TEXT STATETEXT OF THIS;
PROPERTY;
Text "State/Pro&vince:",;
Top 3.9795,;
Height 1.3145,;
Width 16.1768,;
PageNo 1,;
Left 36.4893,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 5
DEFINE ENTRYFIELD STATEENTRY OF THIS;
PROPERTY;
ColorHighLight "B+/W*",;
Top 3.9795,;
Height 1.3145,;
Width 14.1104,;
Enabled .F.,;
PageNo 1,;
DataLink "STATE_PROV",;
Left 53.3896,;
OnChange CLASS::CHANGESMADE,;
Border .T.,;
ColorNormal "N/BtnFace"
DEFINE TEXT ZIPTEXT OF THIS;
PROPERTY;
Text "&Zip Code:",;
Top 5.2998,;
Height 1.3193,;
Width 10.8037,;
PageNo 1,;
Left 2.0293,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 5
DEFINE ENTRYFIELD ZIPENTRY OF THIS;
PROPERTY;
ColorHighLight "B+/W*",;
Top 5.2998,;
Height 1.3193,;
Width 22.3135,;
Enabled .F.,;
PageNo 1,;
DataLink "ZIP_POSTAL",;
Left 13.5195,;
OnChange CLASS::CHANGESMADE,;
Border .T.,;
ColorNormal "N/BtnFace"
DEFINE TEXT COUNTRYTEXT OF THIS;
PROPERTY;
Text "Count&ry:",;
Top 5.2998,;
Height 1.3193,;
Width 14.8262,;
PageNo 1,;
Left 37.8398,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 5
DEFINE ENTRYFIELD COUNTRYENTRY OF THIS;
PROPERTY;
ColorHighLight "B+/W*",;
Top 5.2998,;
Height 1.3193,;
Width 14.1104,;
Enabled .F.,;
PageNo 1,;
DataLink "COUNTRY",;
Left 53.3896,;
OnChange CLASS::CHANGESMADE,;
Border .T.,;
ColorNormal "N/BtnFace"
DEFINE TEXT PHONETEXT OF THIS;
PROPERTY;
Text "P&hone:",;
Top 6.6299,;
Height 1.3105,;
Width 10.8037,;
PageNo 1,;
Left 2.0293,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 5
DEFINE ENTRYFIELD PHONEENTRY OF THIS;
PROPERTY;
ColorHighLight "B+/W*",;
Top 6.6299,;
Height 1.3105,;
Width 22.3135,;
Enabled .F.,;
PageNo 1,;
DataLink "PHONE",;
Left 13.5195,;
OnChange CLASS::CHANGESMADE,;
Border .T.,;
ColorNormal "N/BtnFace"
DEFINE TEXT ORDERSTEXT OF THIS;
PROPERTY;
Text "&Orders:",;
Top 7.9492,;
Height 1.3193,;
Width 10.8037,;
PageNo 1,;
Left 2.0293,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 5
DEFINE BROWSE CHILDBROWSE OF THIS;
PROPERTY;
CUATab .T.,;
FontBold .F.,;
OnLeftDblClick CLASS::CHILDBROWSEDBLCLICK,;
ScrollBar 2,;
Modify .F.,;
Fields "ORDERS->ORDER_NO\H='ORDER NO',ORDERS->TOTAL\9\P='9,999,999.99',ORDERS->SALE_DATE\H='SALE DATE',ORDERS->SHIP_DATE\H='SHIP DATE',ORDERS->AMT_PAID\H='AMT PAID'\P='9,999,999.99',ORDERS->TERMS\12",;
Top 8.2197,;
Height 5.6035,;
ColorHighLight "WindowText/Window",;
Width 72.6465,;
PageNo 1,;
OnNavigate CLASS::BROWSEONNAVIGATE,;
ShowRecNo .F.,;
Alias "ORDERS",;
ShowDeleted .F.,;
Left 13.5195,;
OnChange CLASS::CHANGESMADE,;
Append .F.,;
Delete .F.,;
ColorNormal "N/BtnFace"
DEFINE TEXT SIGNATURETEXT OF THIS;
PROPERTY;
Text "Signature:",;
Top 14.0498,;
Height 1.3027,;
Width 20.3936,;
PageNo 1,;
Left 57.4395,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 3
DEFINE IMAGE SIGNATUREIMAGE OF THIS;
PROPERTY;
Top 15.1494,;
Height 2.5557,;
Width 28.3936,;
PageNo 1,;
Left 57.4395,;
DataSource "BINARY SIGNATURE"
DEFINE TEXT NOTESTEXT OF THIS;
PROPERTY;
Text "No&tes:",;
Top 14.0498,;
Height 1.3027,;
Width 10.8037,;
PageNo 1,;
Left 2.0293,;
Border .F.,;
ColorNormal "B/BtnFace",;
Alignment 5
DEFINE EDITOR NOTESEDITOR OF THIS;
PROPERTY;
OnGotFocus {;if this.Modify;this.colorNormal = "B+/W*";endif},;
CUATab .T.,;
OnLostFocus {;if this.Modify;this.colorNormal = "N/BtnFace";endif},;
Modify .F.,;
Top 14.3193,;
Height 4.21,;
Width 43.3135,;
PageNo 1,;
DataLink "CUSTOMER->NOTES",;
Left 13.5195,;
OnChange CLASS::CHANGESMADE,;
Border .T.,;
ColorNormal "N/BtnFace"
DEFINE IMAGE LOGOIMAGE OF THIS;
PROPERTY;
Top 18.8896,;
Height 2.8154,;
Width 14.8701,;
PageNo 1,;
Left 71.6299,;
DataSource "FILE DIVESHOP.BMP",;
Alignment 1
DEFINE SAMPLEINFOBUTTON CUSTOMERINFOBUTTON OF THIS;
PROPERTY;
Group .T.,;
Top 0.6992,;
Height 1.1826,;
Width 3.5,;
Left 83.5
procedure Open
****************************************************************************
private custNoField, orderField
if type("form.init") = "U"
form.init = .T.
set skip to && Customer.qbe has set skip to orders
set exact off && Customer.qbe has set exact on
set procedure to &_dbwinhome.samples\SampProc.prg additive
*** Do calculations in other area, so form doesn't update on record moves
select select()
use customer again alias temp
custNoField = field(1) && Field customer_n
set order to &custNoField && Tag name is same as field name
go bottom
form.maxCustNo = &custNoField && Max value for the key - used for
&& creating new customers
use
select customer
*** Other setup work
form.inEditMode = .F. && Indicate view/edit state
form.changesMade = .F. && Changes haven't been made yet
form.previousRecord = .F. && Save record number when appending
form.nextCustButton.SetFocus() && Since we are at the first
&& customer, can only move forward
if type("form.parentOrdersForm") <> "U"
form.escExit = .T. && Esc is ok if have parent
form.prevCustButton.enabled = .F. && Disable navigation buttons if
form.nextCustButton.enabled = .F. && called from orders.
form.firstCustButton.enabled = .F.
form.lastCustButton.enabled = .F.
form.root.customer.search.enabled = .F.
form.root.customer.add.enabled = .F.
endif
endif
form.customerInfoButton.sampleName = "Customer.wfm"
form::Open() && Now the form actually opens
****************************************************************************
procedure OnClose
* Clean up.
****************************************************************************
if this.inEditMode
form.ViewEdit() && Finish transaction
endif
&& Close Orders form if it exists
if .not. (type ("form.childOrdersForm") $ "U,L")
form.childOrdersForm.Release()
close procedure &_dbwinhome.samples\Orders.wfm
endif
if type("form.parentOrdersForm") = "U" && If called from Orders.wfm,
&& leave shell(.F.)
shell(.T.)
endif
close procedure &_dbwinhome.samples\SampProc.prg,;
&_dbwinhome.samples\Buttons.cc
****************************************************************************
procedure BrowseOnNavigate
****************************************************************************
if eof()
form.root.customer.viewEdit.enabled = .F.
else
form.root.customer.viewEdit.enabled = .T.
endif
form.CallShowOrders()
****************************************************************************
procedure ChangesMade
* Indicate that changes have been made to the current record
****************************************************************************
form.changesMade = .T.
****************************************************************************
procedure Next
* Go to next record.
****************************************************************************
form.CheckCommit(form.inEditMode)
if .not. eof()
NEXTBUTTON::OnClick()
endif
****************************************************************************
procedure Previous
* Go to previous record.
****************************************************************************
form.CheckCommit(form.inEditMode)
PREVBUTTON::OnClick()
****************************************************************************
procedure ChildBrowseDblClick
* When double click in Orders Browse, bring up Orders.wfm, displaying the
* orders for the current customer
****************************************************************************
form.root.customer.current_orders.OnClick()
****************************************************************************
procedure CheckCommit (newInEditMode)
* Check if must finish transaction.
****************************************************************************
private orderField, changesMade
changesMade = form.changesMade
if form.changesMade .and. form.inEditMode
orderField = field(1) && Field Customer_n
if ConfirmationMessage("Commit changes?",;
FormatStr("Customer %1",&orderField)) = YES
commit()
else
rollback()
if .not. empty(form.previousRecord)
go form.previousRecord
form.previousRecord = .F.
endif
endif
if form.inEditMode .and. newInEditMode
begintrans()
endif
form.changesMade = .F.
endif
if form.inEditMode <> newInEditMode
if newInEditMode && Going to Edit mode
begintrans()
else && Going to View mode
if .not. changesMade
rollback()
endif
endif
form.inEditMode = newInEditMode
endif
****************************************************************************
procedure ViewEdit
* Toggle between View and Edit modes.
****************************************************************************
local inEditMode, editMenu, control
editMenu = form.root.customer.viewEdit
*** If ending edit mode then close transaction, otherwise open it.
if form.inEditMode
form.checkChanged(.F.)
editMenu.text = "&Edit"
editMenu.shortcut = "Ctrl-E"
editMenu.statusMessage = "Edit data."
form.root.customer.delete.enabled = .F. && disabled in view mode
form.CheckCommit(.F.) && Check transaction and
form.text = "Customer -- View Mode" && change mode to View
form.notesEditor.colorNormal = "N/W"
form.childBrowse.modify = .F.
form.notesEditor.modify = .F.
form.statusmessage = "In View Mode. " + ;
"Select Customer - Edit menu to " + ;
"edit/delete data."
form.nextcustbutton.SetFocus()
else && Switch to edit mode
editMenu.text = "Vi&ew"
editMenu.shortcut = "Ctrl-E"
editMenu.statusMessage = "View data."
form.root.customer.delete.enabled = .T. && enabled in edit mode
form.CheckCommit(.T.) && Check transaction and
form.text = "Customer -- Edit Mode" && change mode to Edit
form.childBrowse.modify = .T.
form.notesEditor.modify = .T.
form.statusmessage = "In Edit Mode. " + ;
"Select menu Customer - View to switch " + ;
"to View mode."
form.nameEntry.SetFocus() && Move to the name entryfield
endif
inEditMode = form.inEditMode && Faster if we don't reference a form
control = form.first && variable each time through the loop
do
if .not. control.className $ "BROWSE,EDITOR,NEXTBUTTON,PREVBUTTON,PUSHBUTTON,IMAGE,TEXT"
control.enabled = inEditMode
endif
control = control.before
until control.name = form.first.name
form.custNoEntry.enabled = .F. && Key field is always disabled
form.nameEntry.SetFocus() && Move to the name entryfield
****************************************************************************
procedure CheckChanged(callCommit)
* Check if changes have been made to the current entryfield. This procedure
* is called from menu routines to make sure the form.changesMade gets
* updated when a menu is selected while the changed control has focus.
****************************************************************************
private control, fieldValue, controlValue, typeText, typeValue
if form.inEditMode
control = form.activeControl
if type("control.datalink") <> "U"
fieldValue = control.datalink && name of table field
typeText = type("control.text")
typeValue = type("control.value")
do case
case typeValue = "C"
controlValue = control.value
case typeValue $ "LU" .and. typeText = "C"
controlValue = control.text
otherwise
controlValue = Null
endcase
if controlValue <> &fieldValue
form.changesMade = .T.
endif
endif
endif
if form.changesMade .and. callCommit
CLASS::CheckCommit(form.inEditMode) && Check transactions
endif
****************************************************************************
procedure StartOrdersForm
* Starts the Orders form in it's own session. Note that control returns
* to the current session when this procedure is returned from. This means
* that between the create session command and return you cannot access
* tables in the current session.
****************************************************************************
local custNo
custNo = customer->customer_n && Pass current customer_n into
&& orders form in the new session
create session
set talk off && Set these for the new session
set ldCheck off
set procedure to &_dbwinhome.samples\Orders.wfm additive
form.childOrdersForm = new OrdersForm() && Use Orders.wfm to add, view,
&& edit, or delete an order.
form.childOrdersForm.top = this.top + 2
form.childOrdersForm.left = this.left + 4
form.childOrdersForm.customer_n = custNo
form.childOrdersForm.parentCustomerForm = form && Store a reference to this
&& form so that Orders can
&& call events in this form
form.childOrdersForm.open()
****************************************************************************
procedure CallShowOrders
* Synchronizes the Orders form to the same customer. This is done when
* Customer is run first (form.parentOrdersForm is undefined), and the Orders
* form has been opened (form.childOrdersForm is defined).
****************************************************************************
if type("form.parentOrdersForm") = "U" && Customer is the parent form
if type ("form.childOrdersForm") <> "U" && Orders form has been defined
form.childOrdersForm.ShowOrders(customer->customer_n, orders->order_no)
endif
endif
****************************************************************************
procedure ShowCustomer(custNo)
* Called by Orders.wfm when it is the first form run. Used to synchronize
* this form to the same customer for a given order displayed in Orders.
****************************************************************************
private tempCustNo
form.CheckChanged(.T.)
set order to customer_n
tempCustNo = custNo && Parameters are local so cannot macro
set key to "&tempCustNo" && Only see corresponding customer
go top
ENDCLASS